﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;

namespace Card.Utility
{
    public class MailUtility
    {
        public static void SendSmtpEMail(string strSmtpServer, string strFrom, string strFromDisplayName,string strFromPW, string strTo, string strSubject, string strBody)
        {
            string account = strFrom;
            if (strFrom.EndsWith("@163.com"))
            {
                account = strFrom.Substring(0, strFrom.Length - 8);
            }
            System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential(account, strFromPW);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = false;

            System.Net.Mail.MailMessage message = new MailMessage();
            message.From = new MailAddress(strFrom, strFromDisplayName);
            message.To.Add(strTo);
            message.Subject = strSubject;
            message.Body = strBody;
            message.BodyEncoding = System.Text.Encoding.Default;
            message.IsBodyHtml = false;
            client.Send(message);
        }
    }
}
